<?php
declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class CreateEntityEpisodeRelationTable extends AbstractMigration
{
    public function up()
    {
        $this->table('entity_episode_relation', ['id' => false, 'primary_key' => ['id'], 'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '实体与集关联表'])
            ->addColumn('id', 'integer', ['identity' => true, 'signed' => false, 'limit' => 11, 'comment' => '主键ID'])
            ->addColumn('entity_id', 'integer', ['limit' => 11, 'null' => false, 'signed' => false, 'default' => 0, 'comment' => '实体id'])
            ->addColumn('entity_module_id', 'integer', ['limit' => 11, 'null' => false, 'signed' => false, 'default' => 0, 'comment' => '实体模块id'])
            ->addColumn('episode_id', 'integer', ['limit' => 11, 'null' => false, 'signed' => false, 'default' => 0, 'comment' => '集id'])
            ->addColumn('created', 'integer', ['null' => false, 'default' => 0, 'signed' => false, 'limit' => 11, 'comment' => '创建时间'])
            ->addColumn('project_id', 'integer', ['limit' => 11, 'null' => false, 'signed' => false, 'default' => 0, 'comment' => '项目id'])
            ->addColumn('showings_number', 'string', ['default' => '', 'null' => false, 'limit' => 20, 'comment' => '场次'])
            ->addIndex(['entity_id', 'episode_id','showings_number'], ['type' => 'unique', 'name' => 'idx_entity_id_episode_id_showings_number'])
            ->save();
    }

    public function down()
    {
        $this->table('entity_episode_relation')->drop()->save();
    }
}
